package com.wuyoucar.util;

import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @Author: jiangdz
 * @ProjectName: mywuyou_car
 * @Package: com.wuyou.controller
 * @ClassName: Calculator
 * @Description:
 * @Date: 2020-09-21  18:47
 * @UpdateUser: asus
 * @UpdateDate: 2020-09-21  18:47
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 * @Since JDK 1.8
 */
@Component
public class Calculator {
    /**
     * @param id              保险类型编号
     * @param compensateLines 赔付额度 (万元)
     * @param personnel       车上人员责任险 购买人数
     * @param price           新车购置价
     * @param scratchLines    车身划痕险赔付额度 单位(千元)
     * @param seating         座位数  1 为6座以下  2 6-10座  3 10座以上
     * @param year            购车年限
     * @return insurance      投保所需费用
     * @Description 计算车辆选保所需费用
     * @UpdateTime 2020/9/21 18:58
     */
    public Double calculator(int[] id, int compensateLines, int price, int personnel, int scratchLines, int seating, int year) {
        //交强险 6以一下950  6 座以上 1100
        //投保所需费用
        double insurance = 0;
        //第三者责任险 保费
        double three = 0;
//        车辆损失险保费
        double loss = 0;
        if (id != null) {
            if (seating == 1) {

                for (int i : id) {
                /*
                 * id: 3 是机动车损失保险 ；4 第三者责任保险  ；
                 5 车上人员责任险；6 车身划痕险
                 */
                    if (i == 1) {
                        insurance = 950;
                    } else if (i == 3) {
                        /*
                         * 机动车损失保险
                         */
                        if (year == 1) {
                            insurance = insurance + 630 + price * 0.012;
                            loss = 630 + price * 0.012;
                        } else if (year > 1) {
                            insurance = insurance + 594 + price * 0.012;
                            loss = 594 + price * 0.012;
                        }
                    } else if (i == 4) {
                        /*
                         *  p  赔付额度 (万元) 5万元 516 10万746 20万924  50万1252 100万1630
                         */
                        if (compensateLines == 5) {
                            insurance = insurance + 516;
                            three = 516;
                        } else if (compensateLines == 10) {
                            insurance = insurance + 746;
                            three = 746;
                        } else if (compensateLines == 20) {
                            insurance = insurance + 924;
                            three = 924;
                        } else if (compensateLines == 50) {
                            insurance = insurance + 1252;
                            three = 1252;
                        } else if (compensateLines == 100) {
                            insurance = insurance + 1630;
                            three = 1630;
                        }
                    } else if (i == 5) {
                        /*
                         * 车上人员责任险
                         */
                        insurance = insurance + 50 * personnel;
                    } else if (i == 6) {
                        /*
                         *  车身划痕险 赔付额度(千元) 2千 400 ， 5千 570 ，1万760， 2万1140
                         */
                        if (scratchLines == 2) {
                            insurance = insurance + 400;
                        } else if (scratchLines == 5) {
                            insurance = insurance + 570;
                        } else if (scratchLines == 10) {
                            insurance = insurance + 760;
                        } else if (scratchLines == 20) {
                            insurance = insurance + 140;
                        }
                    }
                }
            } else if (seating == 2) {
                System.out.println("seating = " + seating);
                for (int i : id) {
                /*
                 * id: 1 是机动车损失保险 ；2 第三者责任保险  ；
                 8 车上人员责任险；10 车身划痕险
                 */
                    if (i == 1) {
                        insurance = 1100;
                    } else if (i == 3) {
                        /*
                         * 机动车损失保险
                         */
                        if (year == 1) {
                            insurance = insurance + 756 + price * 0.012;
                            loss = 756 + price * 0.012;
                        } else if (year > 1) {
                            insurance = insurance + 713 + price * 0.012;
                            loss = 713 + price * 0.012;
                        }
                    } else if (i == 4) {
                        /*
                         *  p  赔付额度 (万元) 5万元 516 10万746 20万924  50万1252 100万1630
                         */
                        if (compensateLines == 5) {
                            insurance = insurance + 516;
                            three = 516;
                        } else if (compensateLines == 10) {
                            insurance = insurance + 746;
                            three = 746;
                        } else if (compensateLines == 20) {
                            insurance = insurance + 924;
                            three = 924;
                        } else if (compensateLines == 50) {
                            insurance = insurance + 1252;
                            three = 1252;
                        } else if (compensateLines == 100) {
                            insurance = insurance + 1630;
                            three = 1630;
                        }
                    } else if (i == 5) {
                        /*
                         * 车上人员责任险
                         */
                        insurance = insurance + 50 * personnel;
                    } else if (i == 6) {
                        /*
                         *  车身划痕险 赔付额度(千元) 2千 400 ， 5千 570 ，1万760， 2万1140
                         */
                        if (scratchLines == 2) {
                            insurance = insurance + 400;
                        } else if (scratchLines == 5) {
                            insurance = insurance + 570;
                        } else if (scratchLines == 10) {
                            insurance = insurance + 760;
                        } else if (scratchLines == 20) {
                            insurance = insurance + 140;
                        }
                    }
                }
            } else if (seating == 3) {
                for (int i : id) {
                /*
                 * id: 1 是机动车损失保险 ；2 第三者责任保险  ； 3 全车盗抢险 4 玻璃单独破损险 ；5 自燃损失险 ； 6涉水险 ；7无果责任险
                 8 车上人员责任险；9 不计免赔险；10 车身划痕险
                 */
                    if (i == 1) {
                        insurance = 1100;
                    } else if (i == 3) {
                        /*
                         * 机动车损失保险
                         */
                        if (year == 1) {
                            insurance = insurance + 756 + price * 0.012;
                            loss = 756 + price * 0.012;
                        } else if (year > 1) {
                            insurance = insurance + 713 + price * 0.012;
                            loss = 713 + price * 0.012;
                        }

                    } else if (i == 4) {
                        /*
                         *  p 第三者责任保险  赔付额度 (万元) 5万元 516 10万746 20万924  50万1252 100万1630
                         */
                        if (compensateLines == 5) {
                            insurance = insurance + 516;
                            three = 516;
                        } else if (compensateLines == 10) {
                            insurance = insurance + 746;
                            three = 746;
                        } else if (compensateLines == 20) {
                            insurance = insurance + 924;
                            three = 924;
                        } else if (compensateLines == 50) {
                            insurance = insurance + 1252;
                            three = 1252;
                        } else if (compensateLines == 100) {
                            insurance = insurance + 1630;
                            three = 1630;
                        }
                    } else if (i == 5) {
                        /*
                         * 车上人员责任险
                         */
                        insurance = insurance + 50 * personnel;
                    } else if (i == 6) {
                        /*
                         *  车身划痕险 赔付额度(千元) 2千 400 ， 5千 570 ，1万760， 2万1140
                         */
                        if (scratchLines == 2) {
                            insurance = insurance + 400;
                        } else if (scratchLines == 5) {
                            insurance = insurance + 570;
                        } else if (scratchLines == 10) {
                            insurance = insurance + 760;
                        } else if (scratchLines == 20) {
                            insurance = insurance + 140;
                        }
                    }
                }
            }
        } else {
            id = new int[]{3, 4, 5, 6};
            seating = 1;
            compensateLines = 50;
            scratchLines = 20;
            if (seating == 1) {
                for (int i : id) {
                /*
                 * id: 3 是机动车损失保险 ；4 第三者责任保险  ；
                 5 车上人员责任险；6 车身划痕险
                 */
                    if (i == 1) {
                        insurance = 950;
                    } else if (i == 3) {
                        /*
                         * 机动车损失保险
                         */
                        if (year == 1) {
                            insurance = insurance + 630 + price * 0.012;
                            loss = 630 + price * 0.012;
                        } else if (year > 1) {
                            insurance = insurance + 594 + price * 0.012;
                            loss = 594 + price * 0.012;
                        }
                    } else if (i == 4) {
                        /*
                         *  p  赔付额度 (万元) 5万元 516 10万746 20万924  50万1252 100万1630
                         */
                        if (compensateLines == 5) {
                            insurance = insurance + 516;
                            three = 516;
                        } else if (compensateLines == 10) {
                            insurance = insurance + 746;
                            three = 746;
                        } else if (compensateLines == 20) {
                            insurance = insurance + 924;
                            three = 924;
                        } else if (compensateLines == 50) {
                            insurance = insurance + 1252;
                            three = 1252;
                        } else if (compensateLines == 100) {
                            insurance = insurance + 1630;
                            three = 1630;
                        }
                    } else if (i == 5) {
                        /*
                         * 车上人员责任险
                         */
                        insurance = insurance + 50 * personnel;
                    } else if (i == 6) {
                        /*
                         *  车身划痕险 赔付额度(千元) 2千 400 ， 5千 570 ，1万760， 2万1140
                         */
                        if (scratchLines == 2) {
                            insurance = insurance + 400;
                        } else if (scratchLines == 5) {
                            insurance = insurance + 570;
                        } else if (scratchLines == 10) {
                            insurance = insurance + 760;
                        } else if (scratchLines == 20) {
                            insurance = insurance + 140;
                        }
                    }
                }
            } else if (seating == 2) {
                for (int i : id) {
                /*
                 * id: 1 是机动车损失保险 ；2 第三者责任保险  ；
                 8 车上人员责任险；10 车身划痕险
                 */
                    if (i == 1) {
                        insurance = 1100;
                    } else if (i == 3) {
                        /*
                         * 机动车损失保险
                         */
                        if (year == 1) {
                            insurance = insurance + 756 + price * 0.012;
                            loss = 756 + price * 0.012;
                        } else if (year > 1) {
                            insurance = insurance + 713 + price * 0.012;
                            loss = 713 + price * 0.012;
                        }
                    } else if (i == 4) {
                        /*
                         *  p  赔付额度 (万元) 5万元 516 10万746 20万924  50万1252 100万1630
                         */
                        if (compensateLines == 5) {
                            insurance = insurance + 516;
                            three = 516;
                        } else if (compensateLines == 10) {
                            insurance = insurance + 746;
                            three = 746;
                        } else if (compensateLines == 20) {
                            insurance = insurance + 924;
                            three = 924;
                        } else if (compensateLines == 50) {
                            insurance = insurance + 1252;
                            three = 1252;
                        } else if (compensateLines == 100) {
                            insurance = insurance + 1630;
                            three = 1630;
                        }
                    } else if (i == 5) {
                        /*
                         * 车上人员责任险
                         */
                        insurance = insurance + 50 * personnel;
                    } else if (i == 6) {
                        /*
                         *  车身划痕险 赔付额度(千元) 2千 400 ， 5千 570 ，1万760， 2万1140
                         */
                        if (scratchLines == 2) {
                            insurance = insurance + 400;
                        } else if (scratchLines == 5) {
                            insurance = insurance + 570;
                        } else if (scratchLines == 10) {
                            insurance = insurance + 760;
                        } else if (scratchLines == 20) {
                            insurance = insurance + 140;
                        }
                    }
                }
            } else if (seating == 3) {
                for (int i : id) {
                /*
                 * id: 1 是机动车损失保险 ；2 第三者责任保险  ； 3 全车盗抢险 4 玻璃单独破损险 ；5 自燃损失险 ； 6涉水险 ；7无果责任险
                 8 车上人员责任险；9 不计免赔险；10 车身划痕险
                 */
                    if (i == 1) {
                        insurance = 950;
                    } else if (i == 3) {
                        /*
                         * 机动车损失保险
                         */
                        if (year == 1) {
                            insurance = insurance + 756 + price * 0.012;
                            loss = 756 + price * 0.012;
                        } else if (year > 1) {
                            insurance = insurance + 713 + price * 0.012;
                            loss = 713 + price * 0.012;
                        }

                    } else if (i == 4) {
                        /*
                         *  p 第三者责任保险  赔付额度 (万元) 5万元 516 10万746 20万924  50万1252 100万1630
                         */
                        if (compensateLines == 5) {
                            insurance = insurance + 516;
                            three = 516;
                        } else if (compensateLines == 10) {
                            insurance = insurance + 746;
                            three = 746;
                        } else if (compensateLines == 20) {
                            insurance = insurance + 924;
                            three = 924;
                        } else if (compensateLines == 50) {
                            insurance = insurance + 1252;
                            three = 1252;
                        } else if (compensateLines == 100) {
                            insurance = insurance + 1630;
                            three = 1630;
                        }
                    } else if (i == 5) {
                        /*
                         * 车上人员责任险
                         */
                        insurance = insurance + 50 * personnel;
                    } else if (i == 6) {
                        /*
                         *  车身划痕险 赔付额度(千元) 2千 400 ， 5千 570 ，1万760， 2万1140
                         */
                        if (scratchLines == 2) {
                            insurance = insurance + 400;
                        } else if (scratchLines == 5) {
                            insurance = insurance + 570;
                        } else if (scratchLines == 10) {
                            insurance = insurance + 760;
                        } else if (scratchLines == 20) {
                            insurance = insurance + 140;
                        }
                    }
                }
            }
        }
        System.out.println("insurance = " + insurance);
        //将价格的小数位四舍五入到两位小数
        BigDecimal b = new BigDecimal(insurance);
        double f = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        System.out.println("f = " + f);
        return f;
    }

}

